package com.briup.product_source.controller;

import com.briup.product_source.pojo.ManagerAnimal;
import com.briup.product_source.pojo.ext.ManagerAnimalExt;
import com.briup.product_source.result.Result;
import com.briup.product_source.service.ManagerAnimalService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "动物管理模块")
@RestController
@RequestMapping("/animal")
public class AnimalController {

    @Autowired
    private ManagerAnimalService managerAnimalService;


    @ApiOperation("分页展示模块")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小", defaultValue = "10", required = true),
            @ApiImplicitParam(name = "aGender",value = "动物性别"),
            @ApiImplicitParam(name = "aHealthy",value = "动物健康状况")
    })
    @GetMapping
    public Result queryAndPage(Integer pageNum, Integer pageSize,
                               String aGender, String aHealthy){
        PageInfo<ManagerAnimalExt> pageInfo = managerAnimalService.queryAndPage(pageNum,pageSize,aGender,aHealthy);
        return Result.success(pageInfo);
    }


    @ApiOperation("二维码生成")
    @GetMapping("/QRcode")
    public Result myQRcode(@RequestParam String animalId){
        managerAnimalService.qRCode(animalId);
        return Result.success();
    }


    @ApiOperation("新增或修改动物接口")
    @PostMapping("/saveOrUpdate")
    public Result reviseAnimalInfo(@RequestBody ManagerAnimal animal) {
        managerAnimalService.saveOrUpdate(animal);
        return Result.success();
    }

    @ApiOperation("单个删除")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") String id){
        managerAnimalService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/deleteByIdAll")
    public Result deleteByIdAll(@RequestBody List<String> ids){
        managerAnimalService.deleteByIdAll(ids);
        return Result.success();
    }
}
